/*
 * =====================================================================================
 *
 *       Filename:  OPPSITE_DIR.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2018年12月04日 13时53分13秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *   Organization:  
 *
 * =====================================================================================
 */

#include <stdio.h>
#include <stdlib.h>

enum remap_dir {
    DIR_LAN2WAN = 0,
    DIR_WAN2LAN,
    DIR_LAN2TAP,
    DIR_TAP2LAN,
    DIR_WAN2TAP,
    DIR_TAP2WAN,
    DIR_MAX,
};

char *remap_dir_str[DIR_MAX] = {
    [DIR_LAN2WAN] = "LAN2WAN",
    [DIR_WAN2LAN] = "WAN2LAN",
    [DIR_LAN2TAP] = "LAN2TAP",
    [DIR_TAP2LAN] = "TAP2LAN",
    [DIR_WAN2TAP] = "WAN2TAP",
    [DIR_TAP2WAN] = "TAP2WAN"
};

#define OPPSITE_DIR(dir) (dir==DIR_MAX?dir:(dir%2?(dir-1):(dir+1)))

enum remap_dir opposite_dir(enum remap_dir dir)
{
    if(DIR_MAX == dir) {
        return dir;
    }
    return dir%2?(dir-1):(dir+1);
}

int main(int argc, char **argv)
{
    printf("Input[%s], Output[%s]\n", 
            remap_dir_str[DIR_LAN2WAN],
            remap_dir_str[OPPSITE_DIR(DIR_LAN2WAN)]);
    printf("Input[%s], Output[%s]\n", 
            remap_dir_str[DIR_WAN2LAN],
            remap_dir_str[OPPSITE_DIR(DIR_WAN2LAN)]);
    printf("Input[%s], Output[%s]\n", 
            remap_dir_str[DIR_LAN2TAP],
            remap_dir_str[OPPSITE_DIR(DIR_LAN2TAP)]);
    printf("Input[%s], Output[%s]\n", 
            remap_dir_str[DIR_TAP2LAN],
            remap_dir_str[OPPSITE_DIR(DIR_TAP2LAN)]);
    printf("Input[%s], Output[%s]\n", 
            remap_dir_str[DIR_WAN2TAP],
            remap_dir_str[OPPSITE_DIR(DIR_WAN2TAP)]);
    printf("Input[%s], Output[%s]\n", 
            remap_dir_str[DIR_TAP2WAN],
            remap_dir_str[OPPSITE_DIR(DIR_TAP2WAN)]);

    return 0;
}


